home *** CD-ROM | disk | FTP | other *** search
/ The Essential Home & Business Collection / The Essential Home & Business Collection.iso / 27 / 3 / 5 / HP22D5.ZIP / EXTERN / FF.C < prev    next >
Text File  |  1991-04-16  |  3KB  |  168 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4.  
  5. #include "extern.h"
  6. #include "keycodes.h"
  7.  
  8. extern PTR far GetDTA();
  9. extern far GetFirst(STRING);    /* Mask */
  10. extern far GetNext();
  11.  
  12. PTR near dta;
  13. char near searchspec[80];
  14. char near filespec[80];
  15. char near spec[80];
  16. int near rc;
  17. PTR near t;
  18. HANDLE near hmsg;
  19. BOOLEAN near aborted;
  20.  
  21. int pascal near CheckEscape()
  22.  
  23. {
  24.     MSG Msg;
  25.     do {
  26.         GetEvent(&Msg);
  27.         if ((Msg.Event == EVENT_KEYPRESS) && (Msg.KeyWord == kb_ESCAPE)) {
  28.         return(TRUE);
  29.         }
  30.     } while (Msg.Event != EVENT_IDLE);
  31.     return(FALSE);
  32. }
  33.  
  34. pascal near add()
  35.  
  36. {
  37.     HANDLE hdl;
  38.     int slen;
  39.  
  40.     slen = strlen(searchspec) - 3;
  41.     strncpy(spec,searchspec,slen);
  42.     sprintf(spec+slen,"%s",dta + 30);
  43.  
  44.     hdl = stoh(spec);
  45.     SendPageMsg(hmsg,1,hdl);
  46.     FreeHandle(hdl);
  47. }
  48.  
  49. int pascal near find()
  50.  
  51. {
  52.     HANDLE hDirs = NULL;
  53.     int sz,oldsz;
  54.     PTR p;
  55.  
  56.     if (CheckEscape()) goto abort;
  57.  
  58.     strcpy(spec,searchspec);
  59.     strcpy(spec + strlen(spec) - 3,filespec);
  60.  
  61.     rc = GetFirst(spec);
  62.     while (!rc) {
  63.         if (!(*(BYTE *)(dta + 21) & 0x10)) {
  64.         add();
  65.         }
  66.         rc = GetNext();
  67.     }
  68.  
  69.     sz = 0;
  70.  
  71.     rc = GetFirst(searchspec);
  72.     while (!rc) {
  73.         if (*(BYTE *)(dta + 21) & 0x10) {
  74.         if (*(dta + 30) != '.') {
  75.             oldsz = sz;
  76.             sz += strlen(dta + 30) + 1;
  77.  
  78.             if (oldsz) ReAllocHandle(hDirs,sz);
  79.             else hDirs = NewHandle(sz);
  80.  
  81.             strcpy(deref(hDirs) + oldsz,dta + 30);
  82.         }
  83.         }
  84.         rc = GetNext();
  85.     }
  86.     if (CheckEscape()) goto abort;
  87.  
  88.     p = searchspec + strlen(searchspec) - 3;
  89.     oldsz = 0;
  90.     while (oldsz < sz) {
  91.         t = deref(hDirs) + oldsz;
  92.         strcpy(p,t);
  93.         strcat(p,"\\*.*");
  94.         oldsz += strlen(t) + 1;
  95.         if (find()) {
  96. abort:
  97.         aborted = TRUE;
  98.         sz = 1;
  99.         goto end;
  100.         }
  101.         *(p + strlen(p) - 4) = '\0';
  102.     }
  103.     sz = 0;
  104. end:
  105.     FreeHandle(hDirs);
  106.     return(sz);
  107. }
  108.  
  109. /*
  110. ** FINDFILE
  111. **
  112. ** This routine locates a file anywhere on a disk drive. Each file that is
  113. ** found is sent as a parameter to a handler called "foundFile" so that
  114. ** the pad can process it any way it finds necessary.
  115. **
  116. ** Returns:
  117. **
  118. **    FALSE        normal return value
  119. **    TRUE        the user aborted
  120. **
  121. ** Example:
  122. **
  123. **    get findFile("C","MYFILE.*");
  124. **
  125. **    get findFile(char 1 of the directory,"MYFILE*.*");
  126. **        if it the answer "You aborted!" with "Ok";
  127. */
  128. FindFile(int NumArgs,HANDLE hDrive,HANDLE hFileSpec)
  129.  
  130. {
  131.     if (NumArgs != 2) return(STOP);
  132.  
  133.     sprintf(searchspec,"%c:\\*.*",*deref(hDrive));
  134.     strcpy(filespec,deref(hFileSpec));
  135.  
  136.     dta = GetDTA();
  137.  
  138.     hmsg = stoh("foundFile");
  139.  
  140.     aborted = FALSE;
  141.     find();
  142.  
  143.     FreeHandle(hmsg);
  144.  
  145.     ReturnValue(btoh(aborted));
  146.  
  147.     return(STOP);
  148. }
  149.  
  150. POOL pascal Pool[] = {
  151.     {    "findFile",        /* name of the handler */
  152.         FindFile,         /* pointer to the handler */
  153.         0,            /* reserved */
  154.         FUNCTION},        /* this is a handler, not a function */
  155.  
  156.     {    NULL,            /* NULLs signify the end of the table */
  157.         NULL,
  158.         0,
  159.         0}    };
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.